//
//  CustumTabBarController.m
//  暴走段子_王桂敏
//
//  Created by 王桂敏 on 15/6/1.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "CustumTabBarController.h"
#import "UITabBar+Category.h"
#import "PopingView.h"


@interface CustumTabBarController ()
- (UINavigationController *)_navigationControllerWithClass:(Class)class;//根据制定的视图控制器类型创建对象以及 导航控制器
@end

@implementation CustumTabBarController

- (UINavigationController *)_navigationControllerWithClass:(Class)class{
    WGMTabBarViewController *VC = [[class alloc] init];
    VC.openType = OpenTypeRoot;
    WGMNavigationController *navigaion = [[WGMNavigationController alloc] initWithRootViewController:VC];
    return navigaion;
}

- (void)setup{
    NSArray *imageNames = @[@"icon_civazhicheng",@"icon_wodejigou",@"icon_gerenzhongxin"];
    NSArray *titles = @[@"Civa支撑",@"我的机构",@"个人中心"];
    NSArray *classNames = @[@"HomeViewController",@"SchoolViewController",@"MyViewController",];
    NSMutableArray *viewControllers = [NSMutableArray array];
    for (int i = 0; i < titles.count; i++) {
        UINavigationController *aNavi = [self _navigationControllerWithClass:NSClassFromString(classNames[i])];
        aNavi.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[i] image:[[UIImage imageNamed:imageNames[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:[imageNames[i] stringByAppendingString:@"_active"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [viewControllers addObject:aNavi];
    }
    self.viewControllers = viewControllers;
    self.tabBar.tintColor = GlobalBlue;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
 
    [self.tabBar setTabBarLine];
    [self.tabBar setBackgroundImage:[UIImage imageWithFillColor:WhiteColor Size:CGSizeMake(kScreenWidth, 49)]];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setup];
    
    if (!self.isFirstLogin) {
        self.isFirstLogin = YES;
        PopingView * pop = [[PopingView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:pop];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    if ([self.view window] == nil)// 是否是正在使用的视图
    {
        self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
    }
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
